package com.why.ann;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

/**
 * @author new wei
 * @date 2022/5/16 11:09
 */
@Aspect
@Component
public class MyAspect {
    @Autowired
    HttpServletRequest request;

    @Pointcut(value = "@annotation(com.why.ann.MyAnn)")
    public void pointcut(){

    }
    @Around("pointcut()&&@annotation(myAnn)")
    public Object around(ProceedingJoinPoint joinPoint,MyAnn myAnn) throws Throwable {
        String ip = request.getRemoteAddr();
        String name = joinPoint.getSignature().getName();
        System.err.println("------------拦截方法 ----- "+name+"时间 ----- "+new Date());
        return joinPoint.proceed();
    }
}
